//
//  SLCAShapeLayerController.m
//  Objective-C
//
//  Created by S_Line on 2018/6/29.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLCAShapeLayerController.h"

@interface SLCAShapeLayerController ()

@end

@implementation SLCAShapeLayerController

- (void)initNavBar {
    self.navTitle = @"CAShapeLayer";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavBar];
    
    [self initView];
}

- (void)initView {
    // create path
    UIBezierPath *path = [[UIBezierPath alloc] init];
//    [path moveToPoint:CGPointMake(175, 100)];
    
    [path addArcWithCenter:CGPointMake(150, 100) radius:25 startAngle:0 endAngle:2 * M_PI clockwise:true];
    [path moveToPoint:CGPointMake(150, 125)];
    [path addLineToPoint:CGPointMake(150, 175)];
    [path addLineToPoint:CGPointMake(125, 225)];
    [path moveToPoint:CGPointMake(150, 175)];
    [path addLineToPoint:CGPointMake(175, 225)];
    [path moveToPoint:CGPointMake(100, 150)];
    [path addLineToPoint:CGPointMake(200, 150)];
    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.strokeColor = [UIColor redColor].CGColor;
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.lineWidth = 5;
    shapeLayer.lineJoin = kCALineJoinRound;
    shapeLayer.lineCap = kCALineCapRound;
    shapeLayer.path = path.CGPath;
    
    [self.view.layer addSublayer:shapeLayer];
    
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 250, 100, 50)];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    
    CGRect rect = blueView.bounds;
    CGSize radii = CGSizeMake(10, 10);
    UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
    UIBezierPath *cornerPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii];
    CAShapeLayer *cornerLayer = [[CAShapeLayer alloc] init];
    cornerLayer.path = cornerPath.CGPath;
    blueView.layer.mask = cornerLayer;
}

@end
